package com.cgx.tablet.beeper.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.view.View;

import com.cgx.tablet.beeper.bean.MainButtonBean;
import com.cgx.tablet.beeper.databinding.ItemMainButtonBinding;
import com.cgx.tablet.beeper.interfaces.OnItemClickListener;
import com.yatoooon.screenadaptation.ScreenAdapterTools;


/**
 * CommunityResident
 * Created by Droven on 2017/12/23.
 */

public class MainButtonViewHolder extends RecycleViewHolder<MainButtonBean> implements View.OnClickListener {

    private ItemMainButtonBinding mBinding;
    private OnItemClickListener onItemClickListener;

    public MainButtonViewHolder(View itemView, OnItemClickListener onItemClickListener) {
        super(itemView);
        mBinding = DataBindingUtil.bind(itemView);
        ScreenAdapterTools.getInstance().loadView(itemView);
        mBinding.btnLl.setOnClickListener(this);
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public void Bind(@NonNull MainButtonBean mainButtonBean) {
        mBinding.btnLl.setTag(mainButtonBean.getButtonIv());
        mBinding.btnIv.setImageResource(mainButtonBean.getButtonIv());
        mBinding.btnTv.setText(mainButtonBean.getButtonTv());
    }

    @Override
    public void onClick(View view) {
        if (onItemClickListener != null)
            onItemClickListener.onItemClick(view, getAdapterPosition());
    }
}
